#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
    virtual void BuyTicket() { cout << "买票-全价" << endl; }
};
class Student : public Person
{
public:
    virtual void BuyTicket() { cout << "买票-半价" << endl; }

    /*注意：在重写基类虚函数时，派生类的虚函数在不加virtual关键字时，虽然也可以构成重写(因
   为继承后基类的虚函数被继承下来了在派生类依旧保持虚函数属性),但是该种写法不是很规范，不建议
   这样使用*/
    /*void BuyTicket() { cout << "买票-半价" << endl; }*/
};
void Func(Person &p)
{
}
int main()
{
    Person ps;
    Student st;

    Func(ps);
    Func(st);
    return 0;
}
class A
{
};
class B : public A
{
};
class Person
{
public:
    virtual A *f() { return new A; }
};
class Student : public Person
{
public:
    virtual B *f() { return new B; }
};
class Car
{
public:
    virtual void Drive() final {}
};
class Benz : public Car
{
public:
    virtual void Drive() { cout << "Benz-舒适" << endl; }
};
class Car
{
public:
    virtual void Drive() {}
};
class Benz : public Car
{
public:
    virtual void Drive() override { cout << "Benz-舒适" << endl; }
};
class Car
{
public:
    virtual void Drive() = 0;
};
class Benz : public Car
{
public:
    virtual void Drive()
    {
        cout << "Benz-舒适" << endl;
    }
};
class BMW : public Car
{
public:
    virtual void Drive()
    {
        cout << "BMW-操控" << endl;
    }
};
void Test()
{
    Car *pBenz = new Benz;
    pBenz->Drive();
    Car *pBMW = new BMW;
    pBMW->Drive();
}
